﻿@*指定视图期望的视图模板的模型为 Category 类型*@
@model Blog.Model.Category


@{
    ViewBag.Title = "文章分类";
    Layout = "~/Areas/Admin/Views/Shared/_LayoutEdit.cshtml";
}

@*<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>新增/编辑分类</legend>
    </fieldset>*@

<form class="layui-form" asp-action="CategoryAdd" data-ajax-success="onSuccess" data-ajax="true" data-ajax-method="POST">
    <div class="layui-form-item">
        <label class="layui-form-label">显示名称</label>
        <div class="layui-input-block">
            <input type="text" asp-for="Name" required lay-verify="required" placeholder="请输入类别显示名称" autocomplete="off" class="layui-input" />
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">描述</label>
        <div class="layui-input-block">
            <textarea asp-for="Description" name="Description" placeholder="请输入描述内容" class="layui-textarea"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            @*这是button控件，会提交整个表单*@
            <button class="layui-btn" lay-submit lay-filter="CategoryAdd">保存</button>
            @*<button type="reset" class="layui-btn layui-btn-primary">重置</button>*@
            <input type="button" id="btnClose" class="layui-btn layui-btn-primary" value="关闭" />
        </div>
    </div>

    @Html.HiddenFor(c => c.Id)
    @*要放到form控件里*@
    @*@Html.AntiForgeryToken()*@ @*这个验证在所有的Form表中会自动生成*@
</form>

@section scripts{
    <script>

        var onSuccess = function (res) {

            // 模拟 点击 弹窗的iframe 右上角的 关闭 按钮，为了触发layer.open 的回调事件，从而刷新表格数据
            $('.layui-layer-close,.layui-layer-close*', window.parent.document)[0].click()

            console.log('页面提交成功返回=>' + res);

            //注意：parent 是 JS 自带的全局对象，可用于操作父页面
            //var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
            //console.log('父页面窗口索引=>' + index);

            // 关闭当前iframe
            //parent.layer.close(index);

        }

        $("#btnClose").on('click', function () {

            var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
            // 关闭当前iframe
            parent.layer.close(index);
        });

    </script>
}
